package songhq.sleep;

public class SleepInterrupt {
    public static void main(String[] args) {

        try {
            Thread.sleep(1000);
            new Thread(()->{
                while(true){
                Thread.currentThread().interrupt();//及处于中断标志的线程不能sleep
                try {
                    Thread.sleep(3000);//我的理解就是睡眠必须持有改线程,该线程状态为中断状态

                    //errorException();
                } catch (Exception e) {
                    System.out.println(e.getMessage());
                    System.out.println("睡眠发生了异常");
                    //Thread.currentThread().interrupt();
                }
                System.out.println("子线程方法跑完了");
            }
            }).start();
            System.out.println("main方法跑完了");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    private static void errorException() {
        System.out.println("你好");
        int i = 1/0;
    }
}
